//连接数据库相关的操作在这里
const mysql = require("mysql2");
//1.创建连接池
const connectionPool = mysql.createPool({
  host: "39.105.231.80",
  port: 3306,
  user: "liuyijiang",
  password: "Lyj242526!",
  database: "knowledge_management",
  connectionLimit: 10,
});
//2.获取连接是否成功
connectionPool.getConnection((err, connection) => {
  if (err) {
    console.log("连接失败");
    return;
  } else {
    console.log("和数据库连接成功了,可以进行交互了~");
  }
  connection.connect((err) => {
    if (err) {
      console.log("连接失败");
    } else {
      console.log("和数据库交互测试成功了,可以进行操作了~");
    }
  });
});
//3.获取链接池中连接对象
const connection = connectionPool.promise();
module.exports = connection;
